import time
from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest
from common.broswersetting import broswersetting
class tinyshopDjj(broswersetting):

    def test_djj1(self):
        # 正常添加代金券
        self.tiny_htzh('admin','123456','aaaa')
        self._testMethodName='正常添加代金券'
        self.djj('满500减10','10','500','20')
        time.sleep(1)
        try:
            self.assertIn('代金券模板',self.driver.title)
        except Exception as e:
            self.driver.get_screenshot_as_file('F:\\csxm\\tinyshop_t174\\images\\' + self._testMethodName + '.png')
            raise

    def test_djj2(self):
        self.tiny_htzh('admin', '123456', 'aaaa')
        self._testMethodName = '输入错误积分'
        # 积分输入负数添加代金券
        self.djj('满500减10', '10', '500', '-1')
        time.sleep(1)
        try:
            self.assertIn('积分必需为整数',self.driver.find_element(By.CSS_SELECTOR,'#content > div.message_warning').text)
        except Exception as e:
            self.driver.get_screenshot_as_file('F:\\csxm\\tinyshop_t174\\images\\' + self._testMethodName + '.png')
            raise

    def test_djj3(self):
        # 消费金额输入小数添加代金券
        self.tiny_htzh('admin', '123456', 'aaaa')
        self._testMethodName = '整数位输入小数'
        self.djj('满500减10', '10', '499.99', '20')
        time.sleep(1)
        try:
            self.assertNotIn('订单需满足的最低消费',self.driver.find_element(By.CSS_SELECTOR,'#obj_form > form > dl:nth-child(3) > dd > label').text)

        except Exception as e:
            self.driver.get_screenshot_as_file('F:\\csxm\\tinyshop_t174\\images\\' + self._testMethodName + '.png')
            raise
    def test_djj4(self):
        self.tiny_htzh('admin', '123456', 'aaaa')

        self._testMethodName = '编辑代金券'
        self.djjbj('满400减10', '10', '400')
        time.sleep(1)
        try:
            self.assertIn('代金券模板',self.driver.title)

        except Exception as e:
            self.driver.get_screenshot_as_file('F:\\csxm\\tinyshop_t174\\images\\' + self._testMethodName + '.png')
            raise
    def test_djj5(self):
        self.tiny_htzh('admin', '123456', 'aaaa')

        self._testMethodName = '创建代金券'
        self.cjdjj('2022-11-10', '2022-12-01', '50')
        time.sleep(1)
        try:
            self.assertIn('代金券模板',self.driver.title)

        except Exception as e:
            self.driver.get_screenshot_as_file('F:\\csxm\\tinyshop_t174\\images\\' + self._testMethodName + '.png')
            raise

    def test_djj6(self):
        self.tiny_htzh('admin', '123456', 'aaaa')

        self._testMethodName = '删除代金券'
        self.scdjj()
        time.sleep(1)
        try:
            self.assertIn('代金券模板', self.driver.title)

        except Exception as e:
            self.driver.get_screenshot_as_file('F:\\csxm\\tinyshop_t174\\images\\' + self._testMethodName + '.png')
            raise
if __name__=='__main__':#__name__系统定义的内置变量
   unittest.main()
